package com.dks.controller;


import com.dks.models.QsMail;
import com.dks.repository.IQsMailRepository;

import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("qs-mail")
@RestController
public class QsMailController{

    private IQsMailRepository qsMailRepository;

    @Autowired
    public QsMailController(final IQsMailRepository qsMailRepositoryIn){
        this.qsMailRepository = qsMailRepositoryIn;
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取站内信列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: parentId 家长id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-qs-mail-list")
    public ResultModel<Object> getQsMailList(Integer userId,Integer mainTitleStatus, Integer pageNum, Integer pageSize) {
        if (null == pageNum) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageNum");
        }
        if (null == pageSize) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "pageSize");
        }
        return qsMailRepository.getQsMailList(userId,mainTitleStatus, pageNum, pageSize);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取站内信详情
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-qs-mail-info")
    public ResultModel<Object> getQsMailInfo(Integer userId,Integer mainTitleStatus) {
        if (null == userId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "userId");
        }
        if (null == mainTitleStatus) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "mainTitleStatus");
        }
        return qsMailRepository.getQsMailInfo(userId,mainTitleStatus);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取站内信未读数量
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @return:
     * @throw: 请描述异常信息
     */
    @GetMapping("get-qsMail-unRead-count")
    public ResultModel<Object> getQsMailUnReadCount(Integer userId) {
        if (null == userId) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "userId");
        }
        return qsMailRepository.getQsMailUnReadCount(userId);
    }
    /**
     * @Author: Ah Nan
     * @Description: 标记全部站内信为已读状态
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @return:
     * @throw: 请描述异常信息
     */
    @PostMapping("read-all-qsMail")
    public ResultModel<Object> readAllQsMail(@RequestBody QsMail qsMail) {
        if (null == qsMail.getUserId()) {
            return Result.makeResult(ResultInfo.ERR_PARAM_NULL, "userId");
        }
        return qsMailRepository.readAllQsMail(qsMail.getUserId());
    }
}
